<?php

class acc_DB extends SQLite3 {
	var $acc_db_rs;
	var $acc_rows;

	function __construct() {
		try {  
            $this->open($_SERVER['DOCUMENT_ROOT'] . '/accHestia/db/acc.db');  
        }catch (Exception $e){  
            die($e->getMessage());  
        } 
	}

	function q($ssql){
		$this->acc_db_rs = $this->query($ssql);
		return $this->acc_db_rs;
	}

	//query a word
	function qw($ssql, $key){
		$ret = $this->querySingle($ssql, true);
		if($ret) {
			return $ret[$key];	
		}
		return null;
	}

	function d(){
		$this->close();
		return;
	}

	//query as return effect count
	function afr($ssql) {
		$r = $this->query($ssql);
		if($r) {
			//print_r($r->fetchArray());
			$x = $r->fetchArray(SQLITE3_ASSOC);
			return empty($x) ? 0 : count($x);
		}
		return 0;
	}

	function get_err() {
		return $this->lastErrorMsg();
	}
}

function getQueryResultAsArray($sql, &$outArr) {
	$pdb = new acc_DB();
	$rst = $pdb->q($sql);
    $outArr = array();

	$clCount = $rst->numColumns();
	while($r = $rst->fetchArray(SQLITE3_ASSOC)) {
        $o;
        for ($i = 0; $i < $clCount; $i++) {
            $colName = $rst->columnName($i);
            $o[$colName] = $r[$colName];
        }
        array_push($outArr, $o);
    }
	$pdb->d();
    return 0;
}

?>